//
//  UIButton+Extension.swift
//  MyMicroBlog
//
//  Created by stevenSu on 15/8/2.
//  Copyright © 2015年 stevenSu. All rights reserved.
//

import UIKit
private let fontSize: CGFloat = 12
extension UIButton {
    convenience init(imgName: String, backgroundImgName: String = "timeline_card_middle_background", bgColor: UIColor = UIColor.darkGrayColor(), fontColor: UIColor = UIColor.darkGrayColor(), fontSize: CGFloat = fontSize, title: String) {
        self.init()
        backgroundColor = bgColor
        setBackgroundImage(UIImage(named: backgroundImgName), forState: UIControlState.Normal)
        setBackgroundImage(UIImage(named: backgroundImgName + "_highlighted"), forState: UIControlState.Highlighted)
        setImage(UIImage(named: imgName), forState: UIControlState.Normal)
        setTitleColor(fontColor, forState: UIControlState.Normal)
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)
        setTitle(title, forState: UIControlState.Normal)
    }
    
    convenience init(imgName: String) {
        self.init()
        setImage(UIImage(named: imgName), forState: UIControlState.Normal)
        setImage(UIImage(named: imgName + "_highlighted"), forState: UIControlState.Highlighted)
    }
    
    func setImage(image: UIImage) {
        setImage(image, forState: UIControlState.Normal)
        setImage(image, forState: UIControlState.Highlighted)
    }
}
